package com.example.eschool.fragment;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.eschool.R;
import com.example.eschool.SonActivity;

public class HomeFragment extends Fragment  implements View.OnClickListener{
    View rootview;
    TextView tv_quick,tv_recharge,tv_balance,tv_payCode,tv_school_introduce,
            tv_news,tv_recharge2,tv_record,tv_card_loss,tv_card_relieveloss;
    public HomeFragment() {

    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();


    }

    private void initView() {
        tv_quick = rootview.findViewById(R.id.tv_quick);
        tv_recharge = rootview.findViewById(R.id.tv_recharge);
        tv_balance = rootview.findViewById(R.id.tv_balance);
        tv_payCode = rootview.findViewById(R.id.tv_payCode);
        tv_school_introduce = rootview.findViewById(R.id.tv_school_introduce);
        tv_news = rootview.findViewById(R.id.tv_news);
        tv_recharge2 = rootview.findViewById(R.id.tv_recharge2);
        tv_record = rootview.findViewById(R.id.tv_record);
        tv_card_loss = rootview.findViewById(R.id.tv_card_loss);
        tv_card_relieveloss = rootview.findViewById(R.id.tv_card_relieveloss);

        tv_quick.setOnClickListener(this);
        tv_recharge.setOnClickListener(this);
        tv_balance.setOnClickListener(this);
        tv_payCode.setOnClickListener(this);
        tv_school_introduce.setOnClickListener(this);
        tv_news.setOnClickListener(this);
        tv_recharge2.setOnClickListener(this);
        tv_record.setOnClickListener(this);
        tv_card_loss.setOnClickListener(this);
        tv_card_relieveloss.setOnClickListener(this);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        if (rootview == null){
            rootview=inflater.inflate(R.layout.fragment_home, container, false);
        }
        return rootview;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_quick:
                Intent intent = new Intent(getActivity(), SonActivity.class);
                intent.putExtra("fragment", "tv_quick");
                intent.putExtra("title", "扫一扫");
                startActivity(intent);
                break;


            case R.id.tv_recharge:
            case R.id.tv_recharge2:
                Intent intent1 = new Intent(getActivity(), SonActivity.class);
                intent1.putExtra("fragment", "tv_recharge");
                intent1.putExtra("title", "卡充值");
                startActivity(intent1);
                break;


            case R.id.tv_balance:
                Intent intent2 = new Intent(getActivity(), SonActivity.class);
                intent2.putExtra("fragment", "tv_balance");
                intent2.putExtra("title", "卡余额");
                startActivity(intent2);
                break;


            case R.id.tv_payCode:
                Intent intent3 = new Intent(getActivity(), SonActivity.class);
                intent3.putExtra("fragment", "tv_payCode");
                intent3.putExtra("title", "付款码");
                startActivity(intent3);
                break;


            case R.id.tv_school_introduce:
                Intent intent4 = new Intent(getActivity(), SonActivity.class);
                intent4.putExtra("fragment", "tv_school_introduce");
                intent4.putExtra("title", "学校介绍");
                startActivity(intent4);
                break;


            case R.id.tv_news:
                Intent intent5 = new Intent(getActivity(), SonActivity.class);
                intent5.putExtra("fragment", "tv_news");
                intent5.putExtra("title", "新闻");
                startActivity(intent5);
                break;


            case R.id.tv_record:
                Intent intent7 = new Intent(getActivity(), SonActivity.class);
                intent7.putExtra("fragment", "tv_record");
                intent7.putExtra("title", "交易记录");
                startActivity(intent7);
                break;


            case R.id.tv_card_loss:
                Intent intent8 = new Intent(getActivity(), SonActivity.class);
                intent8.putExtra("fragment", "tv_card_loss");
                intent8.putExtra("title", "卡挂失");
                startActivity(intent8);
                break;


            case R.id.tv_card_relieveloss:
                Intent intent9 = new Intent(getActivity(), SonActivity.class);
                intent9.putExtra("fragment", "tv_card_relieveloss");
                intent9.putExtra("title", "卡解挂");
                startActivity(intent9);
                break;
        }
    }
}